package com.wosai.register.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

public class StringUtil {

    public static String springUrl(String pathInContext)
    {
        return ServletUriComponentsBuilder.fromCurrentContextPath().path(pathInContext).build().toUriString();
    }
    
    public static String intArrayToString(int[] data) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        if (data!=null && data.length>0){
            for(int i: data){
                sb.append(i).append(" ");
            }
        }
        sb.append("]");
        return sb.toString();
    }
    
    public static String readInputStream(InputStream in) {
        StringBuilder sb = new StringBuilder();
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String line = null;
        try {
            while((line = br.readLine())!=null){
                sb.append(line).append("\n");
            }
        }catch(IOException e){
            throw new RuntimeException(e);
        }
        return sb.toString();
    }
}
